/*
 * Copyright 2009 Gary Brown
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 * Change History:
 * 5 April 2009 : Initial version created by gary
 */
package org.betonthemove.ui.android;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.Menu;
import android.view.MenuItem;

public class OptionsMenuSupport {

    private static final int MENU_ACCOUNT_FUNDS = 1;
    private static final int MENU_BETS = 2;
    private static final int MENU_PREFERENCES = 3;
    private static final int MENU_HELP = 4;
    private static final String USER_GUIDE_URI = "http://code.google.com/p/betonthemove/wiki/UserGuide";

	public static boolean onCreateOptionsMenu(Menu menu) {
	    menu.add(0, MENU_ACCOUNT_FUNDS, 0, "Account Funds").setIcon(R.drawable.acctfunds);
	    menu.add(0, MENU_BETS, 0, "View Bets").setIcon(R.drawable.bets);
	    menu.add(0, MENU_PREFERENCES, 0, "Preferences").setIcon(R.drawable.preferences);
	    menu.add(0, MENU_HELP, 0, "Help").setIcon(R.drawable.help);
	    return true;
	}

	/* Handles item selections */
	public static boolean onOptionsItemSelected(Context context, MenuItem item) {
	    switch (item.getItemId()) {
	    case MENU_ACCOUNT_FUNDS:
	    	{
	    		Intent intent = new Intent();
	    		intent.setClass(context, AccountFundsView.class);
	    		context.startActivity(intent);
	    	}
	        return true;
	        
	    case MENU_BETS:
	        {
	        	Intent intent = new Intent();
		        intent.setClass(context, BetView.class);
		        context.startActivity(intent);
	        }
	        return true;
	        
	    case MENU_PREFERENCES:
	        {
	        	Intent intent = new Intent();
		        intent.setClass(context, PreferenceView.class);
		        context.startActivity(intent);
	        }
	        return true;
        
	    case MENU_HELP:
	        {
	        	Uri uri=Uri.parse(USER_GUIDE_URI);
	        	
	        	Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		        context.startActivity(intent);
	        }
	        return true;
	    }
	    return false;
	}
}
